package DBs;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DBAccess {

	private static final String DB_NAME = "com.mysql.jdbc.Driver";
	private static final String DB_URL =  "jdbc:mysql://localhost/menu?" +
			"user=nak&password=nak&" +
			"useUnicode=true&characterEncoding=UTF-8";

	//ＤＢに接続"jdbc:mysql://192.168.1.167/nak?"
	public Connection getConnection() throws Exception{

		Class.forName(DB_NAME);
		Connection conn = DriverManager.getConnection(DB_URL);
		conn.setAutoCommit(false);
		return conn;
	}

	//検索処理
	public ResultSet execSQLQuery(Connection conn, String sql) throws SQLException{
		PreparedStatement pstmt = conn.prepareStatement(sql);
		ResultSet rs = pstmt.executeQuery();
		return rs;
	}
	//検索以外の処理
	public int execSQLUpdate(Connection conn, String sql)throws SQLException{
		PreparedStatement pstmt = conn.prepareStatement(sql);
		return pstmt.executeUpdate();
	}
}
